package com.cvo.scrumtoolkit.client.pannels;

import com.cvo.scrumtoolkit.client.controller.ControllerImpl;
import com.cvo.scrumtoolkit.client.controller.View;
import com.cvo.scrumtoolkit.client.entities.Project;
import com.cvo.scrumtoolkit.client.model.ProjectStore;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.Widget;


public class NewProjectPanel extends Composite {

	private static NewProjectUiBinder uiBinder = GWT
			.create(NewProjectUiBinder.class);

	private ProjectStore projectStore;
	private String[] scrummaster={"Selecteer","Wim Aelvoet","Yves Bosmans","Tsjerk Raeymaekers","Ricardo Cappelle","John De Mars","Jos DM"};

	interface NewProjectUiBinder extends UiBinder<Widget, NewProjectPanel> {
	}

	public NewProjectPanel() {
		initWidget(uiBinder.createAndBindUi(this));
		for(int i=0;i<scrummaster.length;i++){
			lstscrummaster.addItem(scrummaster[i]);
		}
	}
	
	
	@UiField
	TextBox txtprojectname;
	
	@UiField
	ListBox lstscrummaster;
	
	@UiField
	Button btncreate;

	@UiHandler("btncreate")
	void onClick(ClickEvent e) {
	
		
		Project project = Project.createProject();
		project.setProjectname(txtprojectname.getText());
		project.setScrummaster(lstscrummaster.getValue(lstscrummaster.getSelectedIndex()).toString());	
		
		projectStore=ProjectStore.getProjectStore();
		projectStore.addProject(project);	
		
		
		try {
			ControllerImpl.getController().changeView(View.HOME, null, null);
		} catch (Exception ex) {
			// TODO Auto-generated catch block
		}
	}

}
